{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e3bac2e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from numpy import genfromtxt\n",
    "from sklearn import linear_model\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "df074034",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[     nan      nan      nan      nan      nan      nan      nan      nan]\n",
      " [     nan   83.     234.289  235.6    159.     107.608 1947.      60.323]\n",
      " [     nan   88.5    259.426  232.5    145.6    108.632 1948.      61.122]\n",
      " [     nan   88.2    258.054  368.2    161.6    109.773 1949.      60.171]\n",
      " [     nan   89.5    284.599  335.1    165.     110.929 1950.      61.187]\n",
      " [     nan   96.2    328.975  209.9    309.9    112.075 1951.      63.221]\n",
      " [     nan   98.1    346.999  193.2    359.4    113.27  1952.      63.639]\n",
      " [     nan   99.     365.385  187.     354.7    115.094 1953.      64.989]\n",
      " [     nan  100.     363.112  357.8    335.     116.219 1954.      63.761]\n",
      " [     nan  101.2    397.469  290.4    304.8    117.388 1955.      66.019]\n",
      " [     nan  104.6    419.18   282.2    285.7    118.734 1956.      67.857]\n",
      " [     nan  108.4    442.769  293.6    279.8    120.445 1957.      68.169]\n",
      " [     nan  110.8    444.546  468.1    263.7    121.95  1958.      66.513]\n",
      " [     nan  112.6    482.704  381.3    255.2    123.366 1959.      68.655]\n",
      " [     nan  114.2    502.601  393.1    251.4    125.368 1960.      69.564]\n",
      " [     nan  115.7    518.173  480.6    257.2    127.852 1961.      69.331]\n",
      " [     nan  116.9    554.894  400.7    282.7    130.081 1962.      70.551]]\n"
     ]
    }
   ],
   "source": [
    "# 读入数据\n",
    "data = genfromtxt(r\"longley.csv\",delimiter=',')\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c2ed0954",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 234.289  235.6    159.     107.608 1947.      60.323]\n",
      " [ 259.426  232.5    145.6    108.632 1948.      61.122]\n",
      " [ 258.054  368.2    161.6    109.773 1949.      60.171]\n",
      " [ 284.599  335.1    165.     110.929 1950.      61.187]\n",
      " [ 328.975  209.9    309.9    112.075 1951.      63.221]\n",
      " [ 346.999  193.2    359.4    113.27  1952.      63.639]\n",
      " [ 365.385  187.     354.7    115.094 1953.      64.989]\n",
      " [ 363.112  357.8    335.     116.219 1954.      63.761]\n",
      " [ 397.469  290.4    304.8    117.388 1955.      66.019]\n",
      " [ 419.18   282.2    285.7    118.734 1956.      67.857]\n",
      " [ 442.769  293.6    279.8    120.445 1957.      68.169]\n",
      " [ 444.546  468.1    263.7    121.95  1958.      66.513]\n",
      " [ 482.704  381.3    255.2    123.366 1959.      68.655]\n",
      " [ 502.601  393.1    251.4    125.368 1960.      69.564]\n",
      " [ 518.173  480.6    257.2    127.852 1961.      69.331]\n",
      " [ 554.894  400.7    282.7    130.081 1962.      70.551]]\n",
      "[ 83.   88.5  88.2  89.5  96.2  98.1  99.  100.  101.2 104.6 108.4 110.8\n",
      " 112.6 114.2 115.7 116.9]\n"
     ]
    }
   ],
   "source": [
    "# 切分数据\n",
    "x_data = data[1:,2:]\n",
    "y_data = data[1:,1]\n",
    "print(x_data)\n",
    "print(y_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d3fe0689",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.40875510204081633\n",
      "(16, 50)\n"
     ]
    }
   ],
   "source": [
    "# 创建模型\n",
    "# 生成50个值\n",
    "# numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)\n",
    "'''\n",
    "start:返回样本数据开始点\n",
    "stop:返回样本数据结束点\n",
    "num:生成的样本数据量，默认为50\n",
    "endpoint：True则包含stop；False则不包含stop\n",
    "retstep：If True, return (samples, step), where step is the spacing between samples.(即如果为True则结果会给出数据间隔)\n",
    "dtype：输出数组类型\n",
    "axis：0(默认)或-1\n",
    "'''\n",
    "alphas_to_test = np.linspace(0.001,1)\n",
    "# 创建模型，保存误差值\n",
    "model = linear_model.RidgeCV(alphas=alphas_to_test,store_cv_values=True)\n",
    "# sklearn.linear_model.RidgeCV     内置交叉验证的Ridge分类器\n",
    "model.fit(x_data,y_data)\n",
    "\n",
    "# 岭系数\n",
    "print(model.alpha_)\n",
    "# loss值\n",
    "print(model.cv_values_.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5fe45ef3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgQUlEQVR4nO3deXRcZ5nn8e+jfSvtm63VaxLHcWLHibMwQEKTJoEmYTkzhHS6YQiBJiyhYaZZp7uhGXrO9HAGpmEyDqEhQ1g7gUkPYcLSYcliY9lJvOI1XiTLlqxd1i4980eVZaHIUckqqaR7f59zdFR176uq5/Xyq6v3fe+95u6IiEhwpSS7ABERmVsKehGRgFPQi4gEnIJeRCTgFPQiIgGXluwCplJaWur19fXJLkNEZNHYvn37GXcvm2rfggz6+vp6Ghoakl2GiMiiYWbHLrRPQzciIgGnoBcRCTgFvYhIwCnoRUQCTkEvIhJwCnoRkYBT0IuIBFxggn5szPkfvzzIbw60JrsUEZEFJTBBn5JibP7NEf719y3JLkVEZEEJTNADlOVn0tIzkOwyREQWlEAFfUUki5buwWSXISKyoAQq6MvzM2npUdCLiEwUrKCPRIdudB9cEZHzpg16M6sxs6fMbK+Z7TGzj0zR5i4z22lmu8zsWTO7csK+N5jZfjM7ZGafSHQHJiqPZDEwPEbP4Mhcvo2IyKISzxH9CPAxd18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NLAb4EvCvJpcy3NKLDN68l+lvbb8zsCnfvTGZRc+xO4Jvu/t/M7Hrgf5vZWncfS3Zhi8ViPKJvAmomPK+ObZuyjZmlEf11r21eqpsb8fQZM/sj4NPAm919cJ5qmyvT9TkCrAV+ZWZHiY5lPr7IJ2Tj+XtuBB5392F3fwk4QDT4F6t4+vwe4AcA7v4ckEX04l9BFdf/95lYjEG/DVhlZsvMLIPoZOvjk9o8Dvx57PHbgX/12CzHIjVtn81sPfC/iIb8Yh+3hWn67O5d7l7q7vXuXk90XuLN7t6QnHITIp5/2z8mejSPmZUSHco5Mo81Jlo8fT4OvA7AzC4jGvSt81rl/Hoc+LPY6pvrgC53b57NCy66oRt3HzGzDwJPEp2x/4a77zGzzwEN7v448BDRX+8OEZ30eEfyKp69OPv8X4E84Iexeefj7v7mpBU9S3H2OVDi7POTwC1mthcYBf6Duy/a31bj7PPHgAfN7KNEJ2bftZgP3Mzsu0Q/rEtj8w5/DaQDuPsDROchbgMOAX3Au2f9nov4z0tEROKwGIduRERkBhT0IiIBp6AXEQk4Bb2ISMAp6EVEAk5BLyIScAp6EZGA+/98EwXsGJn99AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图\n",
    "# 岭系数跟loss值的关系\n",
    "plt.plot(alphas_to_test,model.cv_values_.mean(axis=0))\n",
    "# 选取的岭系数的位置\n",
    "plt.plot(model.alpha_,min(model.cv_values_.mean(axis=0)),'ro')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2ef25f37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([88.11216213])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(x_data[2,np.newaxis])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
